<?php

namespace App\Admin\Controllers;
use Common\Common;
use Common\ControllerAdBase;
use Common\Models\AppConfig;

class MechanismController extends ControllerAdBase
{

    public function initialize()
    {
        parent::initialize();
    }

    public function categoryAction(){
        $CAppConfigDb = new AppConfig();
        $where['columns'] = 'category,group_name';
        $where['group'] = 'group_name';
        $list = $CAppConfigDb->find($where)->toarray();
        $this->ok($list);
    }

    public function indexAction(){
        $type = $this->params['group_name']?$this->params['group_name']:'';
        $CAppConfigDb = new AppConfig();
        $is_show=1;
        $get_list = $CAppConfigDb->admin_get_list($is_show,$type);
        $this->ok($get_list);
    }



    public function update_indexAction(){
        if(!isset($this->params['list']) || empty($this->params['list'])){
            $this->fail(-1,'没有接收到参数');
        }
        $CAppConfigDb = new AppConfig();
        foreach($this->params['list'] as $key=>$value){
            $c_app_config = $CAppConfigDb->findFirstById($value['id']);
            if(!$c_app_config){
                continue;
            }
            $c_app_config->value = $value['value'];
            if(!$c_app_config->save()){
                continue;
            }
        }
        $this->ok([]);
    }
}
